<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>
    function isArrayLike (array){

        var length = array && array.length;
        return typeof length === "number" && length >=0;
    };

    function each (array,callback){
        if(isArrayLike(array)){
            //使用for循环
            for(var i=0;i<array.length;i++){
                callback && callback(i,array[i]);
            }
        }else{
            //使用for in循环
            for(var k in array){
                callback && callback(k,array[k])
            }
        }
    }


</script>
</html>